package com.blb.zy_community.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blb.zy_community.entity.ResponseResult;
import com.blb.zy_community.entity.ZyVisitor;
import com.blb.zy_community.service.impl.ZyVisitorServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 访客邀请  前端控制器
 * </p>
 *
 * @author 二组
 * @since 2023-06-18
 */
@CrossOrigin
@RestController
public class ZyVisitorController {
    @Autowired
    private ZyVisitorServiceImpl zyVisitorService;
    @GetMapping("/visitor-page")
    public ResponseResult<Page<ZyVisitor>> getVisitorPage(@RequestParam(required = false,defaultValue = "1") Long current,
                                                          @RequestParam(required = false,defaultValue = "5") Long size,
                                                          @RequestParam(required = false,defaultValue = "") String visitorName,
                                                          @RequestParam(required = false,defaultValue = "") String visitorPhoneNumber,
                                                          @RequestParam(required = false,defaultValue = "" ) String visitorDate){
        Page<ZyVisitor> zyVisitorPage = zyVisitorService.FindVisitor(current, size, visitorName, visitorPhoneNumber, visitorDate);
        return ResponseResult.ok(zyVisitorPage);

    }


    @PostMapping("visitor")
    public ResponseResult<String> addVisitor(@RequestBody ZyVisitor zyVisitor){
        zyVisitorService.save(zyVisitor);
        return ResponseResult.ok(zyVisitor);
    }

}
